package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.ETakeoutOrder;
import com.xuetang9.t9.hotel.dto.reqest.TakeoutDTO;
import com.xuetang9.t9.hotel.mapper.condition.impl.TakeoutOrderCondition;
import com.xuetang9.t9.hotel.services.ITakeoutSerive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Classname TakeoutController
 * @Description TODO
 * @Date 2020/3/7 18:22
 * @Created by ASUS
 */
@Controller
@RequestMapping("take")
@ResponseBody
public class TakeoutController {
    @Autowired
    private ITakeoutSerive takeoutSerive;

    @GetMapping("all")
    public List<ETakeoutOrder> all(){
        return takeoutSerive.queryAll();
    }

    @GetMapping("none")
    public List<ETakeoutOrder> none(){
        return takeoutSerive.queryByNone();
    }

    @GetMapping("finish")
    public List<ETakeoutOrder> take(){
        return takeoutSerive.queryByTake();
    }

    @PostMapping("add")
    public boolean add(@RequestBody TakeoutDTO takeoutDTO){
        System.out.println(takeoutDTO);
        Date now = new Date();
        ETakeoutOrder takeoutOrder = new ETakeoutOrder(now,takeoutDTO.getTotalPrice(),takeoutDTO.getState(),takeoutDTO.getRemark(),takeoutDTO.getTakeoutFoods());
        return takeoutSerive.insertTakeout(takeoutOrder);
    }

    @GetMapping("take/{id}")
    public boolean takeMeal(@PathVariable(value = "id", required = true) Long id){//required为false是可以为空
        Date now = new Date();
        return takeoutSerive.takeMeals(id,now);
    }

    @RequestMapping(value = "/show",method = RequestMethod.POST)
    public Map showAll(@RequestBody TakeoutOrderCondition condition){
        Map map = new HashMap();
        map.put("datas",takeoutSerive.queryByAll(condition));
        map.put("count",takeoutSerive.queryByCount(condition));
        return map;
    }
}
